fix bugs specific to big endian machines (#155)
authortsteven4 <tsteven4@users.noreply.github.com>
Wed, 14 Feb 2018 15:25:14 +0000 (08:25 -0700)
committerGitHub <noreply@github.com>
Wed, 14 Feb 2018 15:25:14 +0000 (08:25 -0700)
* round up some loose endians in mapbar.

* round up another endian, this time in mapsend.

* chase the endians out of naviguide.
also, a potential bug with Qstring length vs. encoded string length.

mapbar_track.cc
mapsend.cc
naviguide.cc

index 06851ba7cb7d2fd70027b5663e0ebde44fa86166..34f796a55d114d508fdbe8fff7cbce1d23f5ec3d 100644 (file)
@@ -88,9 +88,14 @@ mapbar_track_read()
   (void) read_datetime(); // start_time currently unused
   (void) read_datetime(); // end_time currently unused
 
-  ushort name[200] = {0};
-  gbfread((void*)name, 1, 200, fin);
-  // At this point, name is a UCS-16 encoded, zero terminated string.
+  ushort name[101];
+  // read 100 UCS-2 characters that are each stored little endian.
+  // note gbfread wouldn't get this right on big endian machines.
+  for (int idx=0; idx<100; idx++) {
+    name[idx] = gbfgetint16(fin);
+  }
+  name[100] = 0;
+  // At this point, name is a UCS-2 encoded, zero terminated string.
   // All our internals use Qt encoding, so convert now.
   track->rte_name = QString().fromUtf16(name);
 
index 37b7be45cffee2098455aced03be6a40056bfbf5..03fed302b720b5f39a0269ad9a169b559357b21e 100644 (file)
@@ -332,7 +332,7 @@ mapsend_waypt_pr(const Waypoint* waypointp)
     }
   }
 
-  gbfwrite(&c, 1, 1, mapsend_file_out);
+  gbfputc(c, mapsend_file_out);
   gbfputc(1, mapsend_file_out);
 
   falt = waypointp->altitude;
index 407370a6f80f8a8605bfafa59a8d9d93a9a33815..82103fb214b6513ce5d3a3014fe76784849c23ad 100644 (file)
@@ -133,8 +133,8 @@ ng_fwrite_wp_data(const QString& s, const QString& d, ng_wp_data_t* wp_data, gbf
   char z[50];
 
   memset(z, 0, 50);
-  i = s.length();
-  gbfwrite(&i, 1, 1, f);
+  i = strlen(STRFROMUNICODE(s));
+  gbfputc(i, f);
   gbfwrite(STRFROMUNICODE(s), 1, i, f);
 
   gbfwrite(&wp_data->pad1[0], 8, 1, f);
@@ -143,8 +143,8 @@ ng_fwrite_wp_data(const QString& s, const QString& d, ng_wp_data_t* wp_data, gbf
   gbfwrite(&wp_data->pad2[0], 2, 1, f);
   gbfputint32(wp_data->Alt, f);
 
-  i = d.length();
-  gbfwrite(&i, 1, 1, f);
+  i = strlen(STRFROMUNICODE(d));
+  gbfputc(i, f);
   gbfwrite(STRFROMUNICODE(d), 1, i, f);
   gbfwrite(z, 44, 1, f);
 }